package com.ym.controller.management;

import cn.hutool.extra.spring.SpringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.ym.core.config.ConfigCenterProperties;
import com.ym.core.config.QiNiuYunConfig;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;

import com.ym.medical.domain.param.ConsultingOrderParam;
import com.ym.medical.domain.vo.ConsultingOrderInfoVO;
import com.ym.medical.domain.vo.ConsultingOrderVO;
import com.ym.medical.service.IInquiryOrderSV;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单相关
 *
 * @author: 李涛
 * @version: 2019年06月24日 14:45
 */
@Api(tags = "订单相关")
@RestController
@RequestMapping("/management/orders")
@Validated
public class OrderController extends BaseController {

	@Autowired
	private IInquiryOrderSV inquiryOrderSV;

	@ApiOperation("咨询订单列表")
	@GetMapping(value = "/consultingOrder/list")
	public APIResponse<PageInfo<ConsultingOrderVO>> consultingOrderList(
			ConsultingOrderParam query,
			@RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int limit
	) {
		PageHelper.startPage(pageNo, limit);
		List<ConsultingOrderVO> data = inquiryOrderSV.consultingOrderList(query);
		return successData(new PageInfo<>(data));
	}

	@ApiOperation("问诊详情页")
	@GetMapping(value = "/consultingOrder/info")
	public APIResponse<ConsultingOrderInfoVO> consultingOrderInfo(
			@RequestParam Long orderId
	) {
		ConsultingOrderInfoVO data = inquiryOrderSV.consultingOrderInfo(orderId);
		QiNiuYunConfig qiNiuYunConfig = SpringUtil.getBean(ConfigCenterProperties.class).getQiNiuYunConfig();
		List<String> realUrl = new ArrayList<>();
		if (data != null && data.getRecordUrl() != null && data.getRecordUrl().size() == 1) {
			realUrl.add(qiNiuYunConfig.getShowRecUrl() + data.getRecordUrl().get(0));
			data.setRecordUrl(realUrl);
		} else if (data != null && data.getRecordUrl() != null && data.getRecordUrl().size() > 1) {
			for (String str : data.getRecordUrl()) {
				realUrl.add(qiNiuYunConfig.getShowRecUrl() + str);
			}
			data.setRecordUrl(realUrl);
		}
		return successData(data);
	}
}
